package bist.believeinstep.impl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import bist.believeinstep.dao.ConnectionDAO;
import bist.believeinstep.dao.TourPriceDAO;
import bist.believeinstep.domain.TourPrice;
import bist.believeinstep.mapper.TourPriceMapper;

public class TourPriceTemplate implements TourPriceDAO, ConnectionDAO {
	private JdbcTemplate jdbcTemplate;
	
	public void setDataSource(DataSource dataSource){
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	@Override
	public void create(TourPrice tourPrice){
		String query = "INSERT INTO bist_tour_prices (baby_price, adult_price"
				+ "children_price, state, created_date, modified_date, created_by, modified_by) "
				+ "VALUES (?,?,?,?,?,?,?,?)";
		try{
			jdbcTemplate.update(query, new Object[]{
				tourPrice.getBabyPrice(),
				tourPrice.getAdultPrice(),
				tourPrice.getChildrenPrice(),
				tourPrice.getState(),
				tourPrice.getCreated(),
				tourPrice.getModified(),
				tourPrice.getCreatedBy(),
				tourPrice.getModifiedBy()
			});
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	@Override
	public void update(TourPrice tourPrice){
		String query = "UPDATE bist_tour_prices SET"
				+ "baby_price = ?"
				+ "adult_price = ?"
				+ "children_price = ?"
				+ "state = ?"
				+ "created_date = ?"
				+ "modified_date = ?"
				+ "created_by = ?"
				+ "modified_by = ?";
		try{
			jdbcTemplate.update(query, new Object[]{
				tourPrice.getBabyPrice(),
				tourPrice.getAdultPrice(),
				tourPrice.getChildrenPrice(),
				tourPrice.getState(),
				tourPrice.getCreated(),
				tourPrice.getModified(),
				tourPrice.getCreatedBy(),
				tourPrice.getModifiedBy()		
			});
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	@Override
	public TourPrice getTourPrice(Integer id){
		String query = "SELECT FROM bist_tour_prices WHERE id = ?";
		try{
			TourPrice tourPrice = jdbcTemplate.queryForObject(query, new Object[]{id}, new TourPriceMapper());
			return tourPrice;
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	@Override
	public List<TourPrice> listTourPrice(){
		String query = "SELECT * FORM bist_tour_prices";
		try{
			List<TourPrice> tourPrice = jdbcTemplate.query(query, new TourPriceMapper());
			return tourPrice;
		}catch(Exception ex){
			ex.printStackTrace();
		}
	return null;
	}
	@Override
	public void delete(Integer id){
		String query = "DELETE FROM bist_tour_prices WHERE id = ?";
		try{
			jdbcTemplate.update(query, new Object[]{id});
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
}
